﻿using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace SS.Common.DBBuilder.DBDataStructure
{
    /// <summary>
    /// Present table corresponding with table from database
    /// </summary>
    public class Table
    {
        #region Properties

        /// <summary>
        /// Table name, it is corresponding with table name from database
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// List attributes of table, it is corresponding with attributes of table from database
        /// </summary>
        public IEnumerable<Attribute> Attributes { get; set; }

        /// <summary>
        /// The database which table refer to
        /// </summary>
        public DataBase DataBase { get; set; }

        #endregion

        #region Ctors

        /// <summary>
        /// Initialize an instance of table based on DataTable input
        /// </summary>
        /// <param name="dtbl">DataTable input</param>
        public Table(DataTable dtbl)
        {
            this.Name = dtbl.TableName;
            this.Attributes = dtbl.Columns.Cast<DataColumn>().Select(n => new Attribute(n)).ToList();
        }

        #endregion
    }
}
